package com.cjkj.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cjkj.common.annotation.Log;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.purchase.domain.PurchaseStorageRecord;
import com.cjkj.purchase.service.IPurchaseStorageRecordService;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.common.core.page.TableDataInfo;

/**
 * 采购材料入库记录Controller
 * 
 * @author cjkj
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/purchase/in/record")
public class PurchaseStorageRecordController extends BaseController
{
    @Resource
    private IPurchaseStorageRecordService purchaseStorageRecordService;

    /**
     * 查询采购材料入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseStorageRecord purchaseStorageRecord)
    {
        startPage();
        List<PurchaseStorageRecord> list = purchaseStorageRecordService.selectPurchaseStorageRecordList(purchaseStorageRecord);
        return getDataTable(list);
    }

    /**
     * 导出采购材料入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "采购材料入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseStorageRecord purchaseStorageRecord)
    {
        List<PurchaseStorageRecord> list = purchaseStorageRecordService.selectPurchaseStorageRecordList(purchaseStorageRecord);
        ExcelUtil<PurchaseStorageRecord> util = new ExcelUtil<PurchaseStorageRecord>(PurchaseStorageRecord.class);
        util.exportExcel(response, list, "采购材料入库记录数据");
    }

    /**
     * 获取采购材料入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(purchaseStorageRecordService.selectPurchaseStorageRecordByRecordId(recordId));
    }

    /**
     * 新增采购材料入库记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "采购材料入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseStorageRecord purchaseStorageRecord)
    {
        return toAjax(purchaseStorageRecordService.insertPurchaseStorageRecord(purchaseStorageRecord));
    }

    /**
     * 修改采购材料入库记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "采购材料入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseStorageRecord purchaseStorageRecord)
    {
        return toAjax(purchaseStorageRecordService.updatePurchaseStorageRecord(purchaseStorageRecord));
    }

    /**
     * 删除采购材料入库记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "采购材料入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(purchaseStorageRecordService.deletePurchaseStorageRecordByRecordIds(recordIds));
    }
}
